#pragma once

#include "Nodes/Defs.h"
#include <string>

template<class Node>
class PostfixPrinter : protected NodeVisitor<Node>
{
	std::string m_result;

public:
    static inline std::string print(Node * node)
    {
    	PostfixPrinter printer;
    	node->accept(&printer);
    	return printer.m_result;
    }

    inline void visitOr(typename NodeTraits<Node>::NodeOr * node)
    {
        node->getChild(0)->accept(this);
        for(size_t i=1; i<node->getChildrenCount(); ++i)
        {
            node->getChild(i)->accept(this);
            m_result += '|';
        }
    }

    void visitAnd(typename NodeTraits<Node>::NodeAnd * node)
    {
        node->getChild(0)->accept(this);
        for(size_t i=1; i<node->getChildrenCount(); ++i)
        {
            node->getChild(i)->accept(this);
            m_result += '&';
        }
    }

    void visitNot(typename NodeTraits<Node>::NodeNot * node)
    {
        node->getChild(0)->accept(this);
        m_result += '~';
    }

    void visitAtom(typename NodeTraits<Node>::NodeAtom * node)
    {
    	m_result += node->getAtomText();
    }
};
